package com.eric.code.oauth2.user;

import com.eric.code.oauth2.intercepter.SessionInterceptor;
import com.eric.code.oauth2.intercepter.SuperUserInterceptor;
import com.eric.code.oauth2.model.User;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

/**
 * Created by eric on 17-3-21.
 */
@Before({SessionInterceptor.class, SuperUserInterceptor.class})
public class UserController extends Controller {

    private UserService srv = UserService.me;

    public void index(){
        setAttr("userPage", srv.paginate(getParaToInt("p", 1)));
        render("index.html");
    }

    public void add(){
        render("add.html");
    }

    public void save(){
        srv.save(getModel(User.class));
        redirect("/user");
    }

    public void edit(){
        render("edit.html");
    }


    public void update(){
        srv.update(getModel(User.class));
        redirect("/user");
    }

    public void del(){
        long id = getParaToLong("id");
        srv.delete(id);
        redirect("/user");
    }


}
